<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<form id=f action="interactive-validation-remove-node-in-handler.html">
<input type=hidden name=submitted value="true">
<input name=i0 required id="i0">
<input type=submit id="s">
</form>
<script>
description('Should not crash or have an assertion failure if a node was removed during an "invalid" event dispatching for the node.');

function handler(event) {
    var node = event.target;
    node.parentNode.removeChild(node);
    gc();
}

function startOrVerify() {
    document.getElementById('i0').addEventListener('invalid', handler, false);
    var query = window.location.search;
    if (query.indexOf('submitted=true') != -1) {
        testPassed('The form was submitted.');
        debug('TEST COMPLETE');
        if (window.testRunner)
            testRunner.notifyDone();
    } else {
        // HTMLFormElement::submit() skips validation. Use the submit button.
        document.getElementById('s').click();
        // Should have no assertion failures.
        testFailed('The form should be submitted.');
    }
}

if (window.testRunner)
    testRunner.waitUntilDone();
window.onload = startOrVerify;
</script>
</body>
</html>
